import { observable, action } from 'mobx';
import { Tools, Toast, Bubble } from 'weaver-mobile';
import { toJS } from 'mobx';
import * as API from './../../apis/attention';
import { getMultiStrFromBase64} from './../../components/follow/followUtil';
const getLabel = Tools.getLabel;
export class FollowStore {
    @observable followId = '';
    @observable followList= [];
    @observable disableArray=[];
    @observable showname='';
    @observable showcolor = '';
    @observable delfollowids = '';
    @observable comStore = '';
    @observable reqid = '';
    @observable viewlist=[];
    requestid= '';
    @action 

    @action
    setRequestId=(requestid)=>{
        this.requestid = requestid;
    }
    @action
    getStore = (val) =>{
        this.comStore = val
    }
    @action
    setState = (params = {}) => {
        Object.keys(params).forEach((key) => {
            this[key] = params[key];
        });
    }
    @action
    getAttentionTypeSet = (params)=>{
        
        API.getAttentionTypeSet(params).then((result)=>{
            result.datas.map((val)=>{
                if(val.checked=="false"){
                    val.checked = false
                }
            })
            if(params=="com"){
                result.datas.map(item=>{
                    this.viewlist.map(it=>{
                        if(it.id==item.id){
                            item.checked = it.checked;
                        }
                    })
                })
                this.viewlist=result.datas
            }else{
                this.disableArray = result.disabledArray  
                this.followList = result.datas
            }
        })
      
    }
    @action
    saveAttentionTypeSet = (params,type) =>{
        API.saveAttentionTypeSet(params).then((result)=>{
            if(type=='single'){
                const theparams = localStorage.getItem( 'params' )
                 API.getWorkflowAttentionTypeSet(theparams).then((result)=>{
                    result.datas.map((val)=>{
                        if(val.checked=="false"){
                            val.checked = false
                        }
                    })
                    result.datas.map(item=>{
                        if(item.showname.indexOf('base64_') > -1){
                            item.showname = getMultiStrFromBase64(item.showname);
                        }
                        this.viewlist.map(it=>{
                            if(it.id==item.id){
                                item.checked = it.checked;
                            }
                        })
                    })
                    this.followList = result.datas;
                    this.viewlist=result.datas;
                })
            }else if(type=='batch' || type == "Cbatch"){
                this.getAttentionTypeSet("com");
            }else{
                this.getAttentionTypeSet("");
            }
        })
    }
    @action
    batchdelAll = (params) =>{
        API.batchdelAll(params).then((data)=>{
            // console.log(data)
        })
    }
    @action
    saveAttention = (params,type) =>{
        API.saveAttention(params).then((result)=>{
            if(params.flag=='workflow'){
                const { queryParams, menuid, onSearch,nowStore, nowScope, setSignRemark, setStore, getData, nowStore: { searchAdvancedStore }, nowViewScope, retainCondition, getRetainDatas} = this.comStore;
                // nowStore.clear()
                onSearch()
            }else if(params.flag=='detail'){
                
            }else if(params.flag=='supervise'){
                const { nowListAd, nowTab,onSearch} = this.comStore;
                // nowListAd.clear();
                onSearch()
                // nowListAd.getData({ url: '/api/workflow/supervise/getSessionkey', method: "POST", params: { tabKey:nowTab,ismobile: 1, _ec_device: true} });
            }else{
                const { getTreeCount, nowTab, nowListAd,tabs,setState,onSearch } = this.comStore;
                onSearch()
            }   
        })
    }
    @action
    getWorkflowAttentionTypeSet =(params) =>{
        API.getWorkflowAttentionTypeSet(params).then((result)=>{
            result.datas.map((val)=>{
                if(val.checked=="false"){
                    val.checked = false
                }
            })
            this.followList = result.datas  
            this.viewlist = result.datas
            localStorage.setItem( 'params', params );   
        })
    }
}